package com.shop.admin.controller;

import com.shop.admin.result.ApiResult;
import com.shop.admin.service.ShopOrderService;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.vo.SeckillPriceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = {"ShopSeckillController"},description = "零食商品秒杀接口")
@RestController
@RequestMapping("/api/seckill")
public class ShopSeckillController {

    @Resource
    private ShopOrderService shopOrderService;
    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "秒杀列表查询",notes = "page,limit")
    public ApiResult list(@ApiParam("参数为：page,limit")@RequestParam Map<String, Object> params){
        PageUtils page = shopOrderService.querySeckillPage(params);
        return ApiResult.ok(page);
    }

    /**
     * 设置秒杀价格
     */
    @PostMapping("/priceupdate")
    @ApiOperation(value = "设置商品秒杀价格",notes = "orderId,priceCost,priceDiscounts,priceSeckill")
    public ApiResult seckill(@ApiParam("参数为：商品id,成本价，优惠价，秒杀价")@RequestBody SeckillPriceVo priceVO){
        if (priceVO.getPriceSeckill().intValue()>=priceVO.getPriceCost().intValue()&&priceVO.getPriceSeckill().intValue()<=priceVO.getPriceDiscounts().intValue()){
            shopOrderService.priceSeckill(priceVO);
            return ApiResult.ok("价格更新成功！");
        }
       else return ApiResult.ok("价格更新不成立");
    }
}
